<?php
/**
 * Introduction: 定时任务
 * @author: 杨陈鹏
 * @email: yangchenpeng@cdlinglu.com
 */

namespace Admin\Controller\Api;


use Think\Controller;

class TimedTaskController extends Controller
{

    /**
     * Introduction: 订单七天自动确认收货
     * @author: 杨陈鹏
     * @email: yangchenpeng@cdlinglu.com
     */
    public function receipt()
    {

        file_put_contents(RUNTIME_PATH.'/timed_task.log',date('Y-m-d H:i:s')."\n",FILE_APPEND);

        $logic = D('Common/Order','Logic');

        //获取所有超过七天未收货的订单
        $order_info = $logic::$model
                    ->where("status = 3 AND end_time < ".NOW_TIME)
                    ->field('id')
                    ->select();

        if(count($order_info) > 0){

            foreach($order_info as $v){

                $distribution_logic = D('Common/Distribution','Logic');

                //计算分销提成
                $distribution_logic::divided($v['id']);

                $datas['receipt_time'] = NOW_TIME;
                $datas['status'] = 4;

                $logic::update([ 'id' => $v['id'] ],$datas);

            }

        }



    }

}